package com.oocl.o2o.admin.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.oocl.o2o.admin.dao.ManagerDao;
import com.oocl.o2o.admin.entity.Manager;
import com.oocl.o2o.admin.entity.Merchant;

@Repository(value="managerDaoImpl")
public class ManagerDaoImpl implements ManagerDao{
	
	@PersistenceContext(name="un")
	private EntityManager em;
	
	
	@Override
	public Manager findByUname(String uname) {
		String jpql ="select m from Manager m where m.uname=:uname";
		List<Manager>managerList = em.createQuery(jpql)
				.setParameter("uname", uname)
				.getResultList();
		if (managerList.isEmpty()) {
			return null;
		}
		else{
			return managerList.get(0);
		}
		
	}


	@Override
	public Manager findByUnameAndPassword(String uname, String password) {
		// TODO Auto-generated method stub
		String jpql ="select m from Manager m where m.uname=:uname and m.password=:password";
		List<Manager>managerList = em.createQuery(jpql)
				.setParameter("uname", uname)
				.setParameter("password", password)
				.getResultList();
		if (managerList.isEmpty()) {
			return null;
		}
		else{
			Manager manager=new Manager();
			manager=managerList.get(0);
			manager.setPassword("");
			return manager;
		}
	}
	
	

}
